<%@page import="java.util.UUID"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@ include file="/WEB-INF/pages/common/taglib.jsp"%>
<%
    String uuid = UUID.randomUUID().toString();
    request.setAttribute("uuid", uuid);
%>
<div class="container-fluid am-margin-top">
<form id="${uuid}_form">
	<input type="hidden" name="id">
	<input type="hidden" name="hasBuilt">
	<input type="hidden" name="dataModelGroupCode">

	<div class="form-group">
		<label>模型名称</label>
		<input type="text" name="name" class="form-control" check-type="required">
	</div>
	<div class="form-group">
		<label>标识</label>
		<input type="text" name="code" class="form-control" check-type="required">
		<p class="help-block">将作为物理表名称,建议以'dm_'开头.</p>
	</div>
	<div class="form-group">
		<label>存储方式</label>
		<select name="storageMode">
			<pf:dataDic var="item" dicCode="DM_STORAGE_MODE">
                 <option value="${item.value}">${item.name}</option>
            </pf:dataDic>
		</select>
		<p class="help-block">目前只支持关系型数据库.</p>
	</div>
	<div class="form-group">
		<input name="isFlow" type="checkbox" value="1">支持流程，
		<input name="isTree" type="checkbox" value="1">支持树形
	</div>
	<div class="form-group">
		<a href="javascript:void(0);" id="${uuid}_submitBt" class="btn btn-primary pull-right">提交</a>
	</div>
</form>
</div>

<script type="text/javascript">
$(function(){
	var id = '${param.id}';
	var dataModelGroupCode='${param.dataModelGroupCode}';
	
	var uuid = '${uuid}';
	var form = $("#" + uuid + "_form");
	form.validation();
	
	$("#" + uuid + "_submitBt").click(function(){
		if (isValid()) {
			form.find(":disabled").removeAttr("disabled");
			form.ajaxSubmit({
				url : ctx + '/dataModelDefAct/save.do',
				data : {},
				type : "POST",
				success : function(data) {
					if (data.success) {
						webUtils.alert("提交成功");
						top.webUtils.topicPublish(
								"tableDefine.edit.success", data);
					} else {
						webUtils.error(data.msg);
					}
				}
			});
		}
	});
	
	function isValid(){
		return form.valid();
    }
	
	
	
	var init=function(){
		if(id){
			form.find("input[name=code]").attr("disabled","disabled");
		}else{
			if(dataModelGroupCode){
				form.find("input[name=dataModelGroupCode]").val(dataModelGroupCode);
			}
		}
		form.find("input[name=name]").blur(function(){
			var $this=$(this);
			var tableCode=form.find("input[name=code]")
			if(!tableCode.val()){
				webUtils.getEn($this.val(),function(str){
					tableCode.val("dm_"+str);
				});
			}
		});
	}
	
	if (id) {
		$.getJSON(ctx + '/dataModelDefAct/findById.do',{id : id},function(data){
			webUtils.fullForm({
				form : form,
				data : data
			});
			
			init();
		});
	}else{
		init();
	}
	
});
</script>